from enum import Enum
from typing import Optional, List

from bct.tools.common.bct4.base_dto import JsonDTO


class ResourceType(Enum):
    BOOK = 'BOOK'


class TradeBookResource(JsonDTO):
    department_id: Optional[str]
    resource_name: Optional[str]
    resource_type: Optional[str]

    def __init__(self, input_dict:dict = None):
        if input_dict:
            self.department_id = input_dict['departmentId']
            self.resource_name = input_dict['resourceName']
            self.resource_type = input_dict['resourceType']

    def to_dict(self):
        return {
            "departmentId": self.department_id,
            "resourceName": self.resource_name,
            "resourceType": self.resource_type
        }


class AuthResource(JsonDTO):
    id: Optional[str]
    parent_id: Optional[str]
    department_id: Optional[str]
    create_time: Optional[str]
    resource_name: Optional[str]
    resource_type: Optional[ResourceType]

    def __init__(self, dict_input: dict = None):
        if dict_input:
            self.id = dict_input['id']
            self.parent_id = dict_input['parentId']
            self.department_id = dict_input['departmentId']
            self.create_time = dict_input['createTime']
            self.resource_name = dict_input['resourceName']
            self.resource_type = ResourceType[dict_input['resourceType']]

    def to_dict(self):
        pass


class Department(JsonDTO):
    id: Optional[str]
    description: Optional[str]
    department_type: Optional[str]
    department_name: Optional[str]
    children: List

    def __init__(self, dict_input: dict = None):
        if dict_input is not None:
            self.id = dict_input['id']
            self.department_name = dict_input['departmentName']
            self.department_type = dict_input['departmentType']
            self.description = dict_input['description']
            if 'children' in dict_input and \
                    dict_input['children'] and \
                    len(dict_input['children']) > 0:
                self.children = []
                for c in dict_input['children']:
                    self.children.append(Department(c))

    def to_dict(self):
        pass
